<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
	<script type="text/javascript" src="scripts/boot.js"></script>
	<style type="text/css">
	 .errorText
	 {
	     color:red;
	 }
	</style>
</head>
<body style="padding: 5px">
	<form id="form1" method="post">
	<input id="id" name="id" class="mini-hidden" value=""/>
        <div style="padding-left:40px;padding-bottom:15px;">
            <table style="width: 100%">
            	<tr>
            		<td style="width:100px;">接收手机号：</td>
                    <td style="width:180px;">    
                        <input name="phoneNum" vtype="int;rangeChar:11,11;numType" class="mini-textbox" required="true" style="width: 300px" />
                    </td>
            	</tr>
            	<tr>
            		<td style="width:100px;">短信模版类型：</td>
            		<td colspan="2"><input class="mini-combobox" url="dictionary_cm_key_val_view.do?typeName=SMS_PHRASE_TYPE"
            			allowInput="false" style="width:300px;" textField="keyValue" valueField="keyName" onvaluechanged="onChanged"/></td>
            	</tr>
            	<tr>
            		<td style="width:100px;">短信模版：</td>
            		<td colspan="2"><input id="smsTemple" class="mini-combobox" allowInput="false" style="width:300px;" textField="content" valueField="id" onvaluechanged="onTempleChanged"/></td>
            	</tr>
            	<tr>
            		<td style="width:100px;">发送内容：</td>
                    <td style="width:180px;">    
                        <input id="smsContent" name="content" class="mini-textarea" required="true" vtype="maxLength:70" style="width: 300px;height: 100px" />
                    </td>
            	</tr>
            </table>
         </div>
    </form>
     <div style="text-align:center;margin-top: 20px">          
        <a class="mini-button" onclick="onOk" style="width:60px;">保存</a>       
        <a class="mini-button" onclick="onCancel" style="width:60px;">取消</a>    
     </div>  

<script type="text/javascript">
	mini.parse();
	var form = new mini.Form("form1");
	var path;
	
	function SetData(data) {
	        //跨页面传递的数据对象，克隆后才可以安全使用
	        data = mini.clone(data);
	        form.setData(data.row);
	        form.setChanged(false);
	        path = data.action;
	}

	function GetData() {
	    var o = form.getData();
	    return o;
	}
	//保存数据
	function SaveData() {
	    var o = form.getData(true); 
	    form.validate();
	    if (form.isValid() == false) return;
	    $.ajax({
	        url: path,
			type: 'post',
			dataType: 'json',
	        data: o,
	        cache: false,
	        success: function (text) {
	            if(text.success){
	            	window.CloseOwnerWindow("succ");
	            }else{
	            	mini.alert("数据错误！");
	            }
	        },
	        error: function (jqXHR, textStatus, errorThrown) {
	            alert(jqXHR.responseText);
	            window.CloseOwnerWindow();
	        }
	    });
	}
	
	function CloseWindow(action) {            
	    if (window.CloseOwnerWindow) return window.CloseOwnerWindow(action);
	    else window.close();            
	}

	function onOk(e) {
	    SaveData();
	}

	function onCancel(e) {
	    CloseWindow("cancel");
	}
	
	function onChanged(e) {
		var newUrl = "sms_phrase_by_type.do?type="+e.value;
		var st = mini.get("smsTemple");
		st.load(newUrl);
	}

	function onTempleChanged(e){
		var sms = mini.get("smsContent");
		sms.setValue(e.selected.content);
	}
	
	//验证号码格式
	mini.VTypes["numTypeErrorText"] = "号码格式不正确";
	mini.VTypes["numType"] = function (v) {
		var reMobile = new RegExp("^0?1[34578]\\d{9}$");
		if(reMobile.test(v)) {
			return true;
		} else {
			return false;
		}
	}
</script>
</body>
</html>